<?php
require_once('../../config.php');
Doctrine::loadModels('../../models');

if ($_REQUEST["agent_id"]) 
{
	$agent_id = strip_tags($_REQUEST["agent_id"]);
	//file_put_contents  ( "param_id.txt", $agent_id);	
	
	$query = $db_query = sprintf("SELECT i.image_id, i.agent_id, i.image_type_id, 
				i.image_name, i.location_name, i.created, i.modified, i.created_by, 
				i.modified_by, 
        		t.item_name image_type 
	FROM agent_images i
  		INNER JOIN lk_glossary t ON aa.type_id = t.item_id
	WHERE i.deleted = 0 AND i.agent_id ='".$agent_id."'");
	
	$items = mysql_query($query);	
}

$dom = new DomDocument('1.0',"UTF-8");
$dom->formatOutput = true;
$root = $dom->createElement( "results" );
$dom->appendChild( $root );
	while(($item = mysql_fetch_assoc($items)))
	{
		$dn = $dom->createElement( "record" );
		$dn->setAttribute( 'agent_id', ($item['agent_id']));
		$dn->setAttribute( 'image_id', ($item['image_id']));
		$dn->setAttribute( 'image_type_id', ($item['image_type_id']));
		$dn->setAttribute( 'image_type', ($item['image_type']));
		$dn->setAttribute( 'image_name', ($item['image_name']));
		$dn->setAttribute( 'location_name', $item['location_name'] );
		$dn->setAttribute( 'created', ($item['created']));
		$dn->setAttribute( 'modified', ($item['modified']));
		$dn->setAttribute( 'created_by', ($item['created_by']));
		$dn->setAttribute( 'modified_by', ($item['modified_by']));
		$root->appendChild( $dn );
	}		
header( "Content-type: text/xml; charset=UTF-8");
echo $dom->saveXML();

/*
 * 
 * Doctrine will not return ID values so using SQL if ($_REQUEST["agent_id"]) 
{
	$agent_id = strip_tags($_REQUEST["agent_id"]);
	file_put_contents  ( "param_id.txt", $agent_id);
	
	$query = new Doctrine_Query();
	
    $query ->select('a.*, t.item_name type, c.name_full country')
    	->from('AgentAddress a')
    	->innerJoin('a.AddressType t')
    	->innerJoin('a.Country c')
    			->where('agent_id ='.$agent_id);
                  
    $items = $query->execute();  
}*/


?>
	
